$(function(){
    let flag = true;
    let kill = false;
    let count = 0;

    // 1. 点击帮助按钮将表示感谢
    $('.help').on('click', ()=>(window.open('https://www.bilibili.com/video/BV1qa411e7Fi/?spm_id_from=333.337.search-card.all.click')));

    // 2. creeper?旁边的小箭头
    $('.more').on('mouseenter mouseleave', function(){
        $('.detail').stop().fadeToggle(300);    
    });

    // 3.你点击了搜索对吧
    $('.search-box button').on('click', function(){
        if ($('.search-box input').val() != ''){
            if (flag) {
                flag = false;
                flyButton();
                $('.search-box input').slideUp(100);
                letsDo();
            }
        }
        
    });

    // 3.1 文本框发射力
    function flyButton(){
       $('.search-box button').removeClass('dancing01');
       $('.search-box button').addClass('dancing02');
       $('.search-box button').animate({width: 673}, 300, function(){
        $('.search-box').css('border', 'none').find('button').text('→ 别 想 搜 索 哦 ←');
    });
       $('.search-box button').animate({top:400}, 400);
    }

    function letsDo(){
        $('.logo').slideUp(200);
        $('.main-content').slideDown();
        playMusic();
        kill = true;
    }

    function playMusic(){
        let music = $('<audio src="media/forget.m4a" loop="loop"></audio>');
        $('.main-content').append(music);
        music[0].play();
    }

    // 4 点击生成搜索之矛
    $('document, html').on('click', function(e){
        if (!flag && kill) {
            kill = false;
            count++;
            let x = e.pageX - 30;
            let y = e.pageY - 30;
            // 创建新的点击点
            let sword = $('<li class="sword">搜索</li>');
            sword.css({
                top: y,
                left: x
            });
            $('.scabbard').append(sword);
            sword.animate({
                fontSize: 0,
                lineHeight: 0,
                width: 0,
                height: 0,
                opacity: 0
            }, 500, function(){
                kill = true;
                $('.main-content ul').empty();
            });
        }

        if (count == 10){
            $('.search-box').css('border', 'none').find('button').text('~ 你 还 挺 真 诚 的 嘛 ~');
        } else if (count == 20) {
            $('.search-box').css('border', 'none').find('button').text('~ i i yo ko i yo ~');
        } else if (count == 30) {
            let url = 'https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=' + $('.search-box input').val();
            window.open(url);
        }
    });



})